#include <iostream>
#include <string>
#include <vector>
using namespace  std;

class Solution {
public:
    bool isNumber(string s) {
        removeBlank(s);
        if(s.size() == 0) return false;

        checkSignal(s);
        if(s.size() == 0) return false;

        string left = findE(s);
        if(left.size() == 0 || s.size() == 0) return false;


        bool resultLeft = checkNum(left);
        int resultRight = checkNum(s);
        removeBlank(s);
        // return s.size() == 0 && resultLeft && resultRight == 1;
        return s.size() == 0 && resultLeft && resultRight == 1;
    }

    void removeBlank(string& s){
        while(s.size() > 0){
            if(s[0] == ' '){
                if(s.size() == 1) s = string();
                else s = string(s, 1);
            }
            else return;
        }
    }

    void checkSignal(string & s){
        if(s[0] == '+' || s[0] == '-')
            s = string(s, 1);
        return;
    }

    string findE(string& s){
        int i = 0;
        for(; i < s.size(); i++){
            if(s[i] == 'e' || s[i] == 'E')
                break;
        }
        if(i == 0)
            return string();
        string result(s, 0, i);
        if(i != s.size())
            s = string(s, i + 1);
        else s = string();
        return result;
    }

    int checkNum(string& s){
        int result = 0;
        for(int i = 0; i < s.size(); i++){
            if(s[i] >= '0' && s[i] <= '9' ){
                if(result == 0)
                    result = 1;
                continue;
            }
            else if(s[i] == '.' && result != 2 ){
                if(s.size() == 1)
                    return 0;
                result = 2;
            }
            else{
                s = string(s, i);
                return result;
            }
        }
        s = string();
        return result;
    }
};

class Solution2 {
public:
    string deleteText(string article, int index) {
        if(article[index] == ' ') return article;
        int i  = 0, j = 0;
        while(index != i || article[index - i] != ' ' )
            i ++;
        while(index + i != article.size() - 1 || article[index + i] != ' ' )
            j ++;

        if(index != i)
            return string(article, 0, index - i) + string(article, index + j);
        else if( index + i != article.size() - 1)
            return string(article, index + i);
        else return string();
    }
};
int main() {
    Solution2 sol;
    string str("Singing dancing in the rain");
    sol.deleteText(str, 10);
    Solution solve;
    bool result = solve.isNumber(string("0"));
    string aaa = "abcd";
    string bbb = string(aaa, 0, 2);
    cout<<*(--aaa.end())<<endl;
    std::cout << "Hello, World!" << std::endl;
    return 0;
}
